home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0193.ZIP / ALT.PAS < prev    next >
Pascal/Delphi Source File  |  1986-02-08  |  5KB  |  89 lines

  1. program Alt_Key; { Accepts an alpha or numeric command line parameter,
  2.                    producing a simulated keyboard input of the
  3.                    corresponding Alt-key combination.
  4.                    e.g. entering... alt P <CR>  at the DOS command
  5.                    prompt will produce the effect of pressing <Alt><P>.
  6.                    The purpose is to permit the activation of Super Key
  7.                    or similar keyboard macros from within batch files.
  8.                    The Key_In procedure can be included in Turbo programs
  9.                    thus permiting you to activate Super Key macros without
  10.                    requiring the user to press a key. }
  11.  
  12. { These routines are hardware dependent and work only on IBM-PC compatibles.
  13.   They require Turbo 3.0 or later due to the use of ParamCount and ParamStr.
  14.   If you are using an earlier version of Turbo you could write your own
  15.   routines to produce the same effect. }
  16.  
  17.   procedure Clr_Kbd_Buf;
  18.     var kbd_head  : Byte absolute $0000:$041A;
  19.     var kbd_tail  : Byte absolute $0000:$041C;
  20.  
  21.     begin
  22.       kbd_head := kbd_tail;
  23.     end; { Clr_Kbd_Buf }
  24.  
  25.   procedure Key_In(in_chr: Integer);
  26.     var bool_val : Boolean;
  27.  
  28.     {  Causes a character to be received as if a key had been pressed.
  29.        in_chr is an integer representing the character to be received.
  30.        If the character is an ASCII character or part of the extended
  31.        character set (#128..#255) the integer will be in the range
  32.        0..255. If a `special' key, function key or Alt key combination
  33.        is to be received in_chr should equal the scan code of the
  34.        desired key * 256. e.g. The scan code for <Alt><1> is 120 decimal
  35.        $78 hex, so in_chr should be 30720 decimal or $7800 hex to produce
  36.        the effect of pressing <Alt><1>. }
  37.  
  38.     begin
  39.       Clr_Kbd_Buf;      { Make sure buffer is empty. Optional depending on    }
  40.       inline            { application.                                        }
  41.       ($1E/             {      PUSH    DS          Save DS and change it      }
  42.        $B8/$40/$00/     {      MOV     AX,0040     to point to seg 0040:      }
  43.        $8E/$D8/         {      MOV     DS,AX                                  }
  44.        $FA/             {      CLI                 Clear interrupt flag       }
  45.        $8B/$46/$04/     {      MOV     AX,[BP+04]  Move character to AX       }
  46.        $8B/$1E/$1C/$00/ {      MOV     BX,[001Ch]  Move kb buf tail Ofs to BX }
  47.        $89/$07/         {      MOV     [BX],AX     Put character in buffer.   }
  48.        $83/$C3/$02/     {      ADD     BX,+2       Increment tail pntr by 2.  }
  49.        $3B/$1E/$82/$00/ {      CMP     BX,[0082h]  Compare BX with [0040:0082]}
  50.        $74/$07/         {      JZ      CIRC        Jump if end of buffer.     }
  51.        $89/$1E/$1C/$00/ {      MOV     [001Ch],BX  Update address of tail.    }
  52.        $EB/$09/$90/     {      JMP     EXIT        Exit                       }
  53.        $8B/$1E/$80/$00/ {CIRC: MOV     BX,[0080h]  Set BX to start of buffer. }
  54.        $89/$1E/$1C/$00/ {      MOV     [001Ch],BX  Update address of tail.    }
  55.        $FB/             {EXIT: STI                 Set interrupt flag.        }
  56.        $1F);            {      POP     DS          Restore DS.                }
  57.       bool_val := KeyPressed; { Force Turbo to check for a keyboard input.    }
  58.     end; { Key_In }
  59.  
  60.  
  61. const alt_alpha : string[35] = 'QWERTYUIOP    ASDFGHJKL     ZXCVBNM';
  62.       alt_num   : string[10] = '1234567890';
  63.  
  64. var param_chr : Char;
  65.     alt_keys  : set of Char;
  66.  
  67. { As shown the ALT command will only accept parameters consisting of the
  68.   alpha charater set and the numbers 0..9. The resulting keyboard input
  69.   generated will be the Alt key in combination with the parameter. The
  70.   Key_In procedure can produce function key combinations and the `special'
  71.   keys (e.g. Ins, Home etc.), however it is not as easy to represent these
  72.   keys with a DOS command line entry. }
  73.  
  74. begin { Alt_Key }
  75.   alt_keys := (['A'..'Z'] + ['0'..'9']);
  76.   if (ParamCount = 1) then { Proceed if there is exactly one cmd line param.}
  77.     begin
  78.       param_chr := ParamStr(1); param_chr := UpCase(param_chr);
  79.       if (param_chr in alt_keys) then
  80.         if (Pos(param_chr,alt_num) > 0) then
  81.           Key_In((Pos(param_chr,alt_num) + 119) * 256)
  82.         else
  83.           Key_In((Pos(param_chr,alt_alpha) + 15) * 256)
  84.     end
  85.   else
  86.     WriteLn('A single character parameter is required. (A-Z or 0-9)');
  87. end. { Alt_Key }
  88.  
  89.